package cn.daqisoft.controller;

import cn.daqisoft.service.RolesService;
import cn.daqisoft.util.ResultUtil;
import cn.daqisoft.vo.RolesInfo;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description:发起webSocket服务的控制层
 * @auther: dream breeze
 * @date: 2018/10/27 18:22
 */
@Controller
@RequestMapping("/cartonOptimization")
public class CartonOptimizationController {
    @Autowired
    private RolesService rolesService;

    /**
     * 获取测试数据列表
     *
     * @return
     */
    @RequestMapping("/getRoleList1")
    @ResponseBody
    public ResultUtil getRoleList1() {
        JSONObject result = new JSONObject();
        result.put("roleList", rolesService.getRolesList1());
        return ResultUtil.renderSuccess("成功", result);
    }

    /**
     * 保存修改数据
     *
     * @return
     */
    @RequestMapping("/saveRole1")
    @ResponseBody
    public ResultUtil saveRole1(@RequestBody RolesInfo rolesInfo) {
        int update = rolesService.update1(rolesInfo);
        if(update == 1){
            return ResultUtil.renderSuccess("修改成功");
        }else{
            return ResultUtil.renderError("修改失败");
        }
    }

    /**
     * 获取测试数据列表
     *
     * @return
     */
    @RequestMapping("/getRoleList2")
    @ResponseBody
    public ResultUtil getRoleList2() {
        JSONObject result = new JSONObject();
        result.put("roleList", rolesService.getRolesList2());
        return ResultUtil.renderSuccess("成功", result);
    }

    /**
     * 保存修改数据
     *
     * @return
     */
    @RequestMapping("/saveRole2")
    @ResponseBody
    public ResultUtil saveRole2(@RequestBody RolesInfo rolesInfo) {
        int update = rolesService.update2(rolesInfo);
        if(update == 1){
            return ResultUtil.renderSuccess("修改成功");
        }else{
            return ResultUtil.renderError("修改失败");
        }
    }

    /**
     * 获取测试数据列表
     *
     * @return
     */
    @RequestMapping("/getRoleList3")
    @ResponseBody
    public ResultUtil getRoleList3() {
        JSONObject result = new JSONObject();
        result.put("roleList", rolesService.getRolesList3());
        return ResultUtil.renderSuccess("成功", result);
    }

    /**
     * 保存修改数据
     *
     * @return
     */
    @RequestMapping("/saveRole3")
    @ResponseBody
    public ResultUtil saveRole3(@RequestBody RolesInfo rolesInfo) {
        int update = rolesService.update3(rolesInfo);
        if(update == 1){
            return ResultUtil.renderSuccess("修改成功");
        }else{
            return ResultUtil.renderError("修改失败");
        }
    }
}
